home *** CD-ROM | disk | FTP | other *** search
/ Programmer Power Tools / Programmer Power Tools.iso / surfmodl / surfm203.arc / SURFSRC.ARC / GETKEY.INC < prev    next >
Text File  |  1988-01-19  |  882b  |  35 lines

  1. function GETKEY: integer;
  2.  
  3. { Wait for a single keypress from the keyboard. Valid keys are 1 thru 9,
  4.   and the function keys from 1 thru 9. Getkey returns an integer
  5.   equal to the value of the keypress (PF1 considered identical to the
  6.   digit 1).
  7. }
  8. var c: char;           { value from keypress }
  9.     Result: integer;   { result of keypress }
  10.  
  11. begin
  12.  
  13.   { clear keyboard buffer }
  14.   while keypressed do
  15.     c := readkey;
  16.  
  17.   { Pause for Keypress }
  18.   while (NOT keypressed) do
  19.     c := ' ';
  20.  
  21.   c := readkey;
  22.   if (c = #0) and (keypressed) then begin    { NUL character (fcn key) }
  23.     c := readkey;
  24.     Result := ord(c) - 58;
  25.   { Treat a spacebar like a 0 }
  26.   end else if (ord(c) = 32) then
  27.     Result := 0
  28.   else
  29.     Result := ord(c) - 48;
  30.   if (Result > 0) and (Result < 10) then
  31.     Getkey := Result
  32.   else
  33.     Getkey := 0;
  34. end; { function GETKEY }
  35.